import request from '@/sheep/request';

export default {
	/**
	 * 获取商品列表
	 */
	getCardList: (data) =>
		request({
			url: '/api/v1/cart',
			method: 'GET',
			custom: {
				showLoading: true,
				auth: true,
				showSuccess: false,
				loadingMsg: '加载中',
				successMsg: '加载完成'
			},
		}),

	/**
	 * 添加购物车
	 */
	appendCart: (data) =>
		request({
			url: '/api/v1/cart/item/add',
			method: 'POST',
			custom: {
				showSuccess: true,
				successMsg: '已添加到购物车~',
			},
			data: {
				...data
			},
		}),

	/**
	 * 删除购物车
	 */
	deleteCart: (id) =>
		request({
			url: `/api/v1/cart/item/${id}`,
			method: 'DELETE',
			custom: {
				showSuccess: true,
				successMsg: '删除成功',
			},
		}),

	/**
	 * 更新购物车
	 */
	updateCart: (data) =>
		request({
			url: '/api/v1/cart/item/update',
			method: 'POST',
			data: {
				...data
			},
			custom: {
				showSuccess: false
			}
		}),

	/**
	 * 获得分享页面二维码
	 */
	getShareQrCode: (data) =>
		request({
			url: `/api/v1/shareImage/add`,
			method: 'POST',
			data,
			custom: {
				showLoading: true,
				showSuccess: false,
			},
		}),

	/**
	 * 切换购物袋亮显状态
	 */
	changeCartState: (id) =>
		request({
			url: `/api/v1/cart/item/image/${id}`,
			method: 'DELETE',
		}),
};